<template>
  <el-card class="box-card">
    <template #header>
      <div class="card-header">
        <span>登录</span>
      </div>
    </template>
    <div class="text item">
      <el-form ref="formRef" :model="loginForm" label-width="120px">
        <el-form-item label="医生编码">
          <el-input v-model="loginForm.docCode"></el-input>
        </el-form-item>
        <el-form-item label="登录密码">
          <el-input v-model="loginForm.password" type="password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </el-card>
</template>

<script setup>
import { ref } from 'vue';
import router from '@/router';
import { Store } from 'vuex';
import axios from '@/plugins/axios';
let store = new Store();

let loginForm = ref({
  docCode: '',
  password: ''
});

/**
 * 医生登录
 */
const login = async () => {
  try {
    const response = await axios.post('http://localhost:9000/doctor/login',
    `docId=${loginForm.value.docCode}&password=${loginForm.value.password}`);
    if (response.data.code === 200) {
      sessionStorage.setItem('doctor', JSON.stringify(response.data.data));
      // store.commit('setUser', response.data.data);
      router.push('/ordersList');
    } else {
      alert(response.data.message);
    }
  } catch (error) {
    alert(error);
  }
};


</script>

<style scoped>
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.box-card {
  width: 400px;
  margin: 0 auto;
  margin-top: 150px;
}
</style>